<?php

use think\migration\Migrator;
use think\migration\db\Column;

class User extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
	    $table = $this->table('user', [ 'engine' => 'MyISAM' ]);
	    $table->addColumn('username', 'string', [ 'limit' => 20, 'default' => '', 'comment' => '用户名' ])
		    ->addColumn('password', 'string', [ 'limit' => 32, 'default' => md5('123456'), 'comment' => '用户密码' ])
		    ->addColumn('mobile', 'string', [ 'limit' => 12, 'default' => '', 'comment' => '手机号码' ])
		    ->addColumn('status', 'integer', [ 'limit' => 1, 'default' => 1, 'comment' => '登陆状态 1登录 2封禁' ])
		    ->addColumn('ios_token', 'string', [ 'limit' => 50, 'default' => '', 'comment' => 'ios token值' ])
		    ->addColumn('android_token', 'string', [ 'limit' => 50, 'default' => '', 'comment' => 'Android token值' ])
		    ->addColumn('web_token', 'string', [ 'limit' => 50, 'default' => '', 'comment' => 'web token值' ])
		    ->addColumn('activity_time', 'integer', [ 'default' => 0, 'comment' => '最后活跃时间' ])
		    ->addColumn('create_time', 'integer', [ 'default' => 0, 'comment' => '' ])
		    ->addColumn('update_time', 'integer', [ 'default' => 0, 'comment' => '' ])
		    ->addColumn('delete_time', 'integer', [ 'null' => true, 'comment' => '软删除' ])
		    ->addIndex([ 'username', 'mobile' ], [ 'unique' => true ])
		    ->create();
    }
}
